<template>
  <div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column
        prop="id"
        label="日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="时间"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱">
      </el-table-column>
      <!--操作按钮-->
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页栏-->
    <el-pagination
      background
      layout="prev, pager, next, jumper, ->, total, slot"
      @current-change="pageQuery"
      :page-count="currentpage"
      :page-size="pagesize"
      :total="totals">
    </el-pagination>
  </div>
</template>

<script>
// import axios from "axios";
export default {
  data () {
    //组件的数据
    return {
      tableData:[],//表格展示的数据
      totals:0,//总数据数量，默认0，被赋值
      pagesize:5,//当前页总数量
      currentpage:1,//当前页码，默认1，被赋值
    }
  },
  methods: {
   /* handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },*/
    getStu(){//https://www.fastmock.site/mock/e6da1268d059d5fde8a9112b77ea3286/pethome/user/list
      this.$http.post("/stu/list",{"currentPage":this.currentpage,"pageSize":this.pagesize}).then(req=>{
        this.tableData=req.data.data//将当前页数据赋值给表格
        console.log(req.data.totals)
        this.totals=req.data.totals//将数据总数赋值给表格的分页参数
      }).catch(req=>{
      })
    },
    //当前页改变时出发事件，回调当前页页数
    pageQuery(page){
      this.currentpage=page;//将当前页页数，赋值给表格分页参数-当前页
      this.getStu();//赋值完重新发请求，传参数，获取数据
    }
  },
  mounted() {
    this.getStu();//页面加载完成之后，发请求，传参数，获取数据
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
